package com.ymm.web.controller;

import com.ymm.platform.api.constants.dto.DriverShowDTO;
import com.ymm.platform.api.constants.dto.QueryOrderDTO;
import com.ymm.platform.api.constants.entity.DriverEntity;
import com.ymm.platform.api.facade.PlatformQueryDriverService;
import com.ymm.platform.api.facade.PlatformQueryOrderService;
import com.ymm.platform.api.utils.Result;
import com.ymm.platform.api.utils.ResultCodeEnum;
import com.ymm.system.api.facade.SystemOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @Company: CUG
 * @Description: TODO
 * @Author: chencong
 * @Date: 2022-08-15 15:05
 **/
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/platform/order")
public class OrderController {

    @Reference
    PlatformQueryOrderService platformQueryOrderService;

    @Reference(version = "server")
    SystemOrderService systemOrderService;
    
    /**
    * @Author: chencong
    * @Description: 分页获取所有订单
    * @DateTime: 14:31 2022/8/16
    * @Params: [pageNum, pageSize]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrder")
    public Result queryAllOrder(Integer pageNum,Integer pageSize) {
        return platformQueryOrderService.queryAllOrder(pageNum,pageSize);
    }
    
    /**
    * @Author: chencong
    * @Description: 分页获取所有进行中的订单
    * @DateTime: 14:31 2022/8/16
    * @Params: [pageNum, pageSize]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderOnP")
    public Result queryAllOrderOnP(Integer pageNum,Integer pageSize) {
        return platformQueryOrderService.queryOrderInProgress(pageNum,pageSize);
    }

    /**
    * @Author: chencong
    * @Description: 分页获取所有完成的订单
    * @DateTime: 14:40 2022/8/16
    * @Params: [pageNum, pageSize]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderOnC")
    public Result queryAllOrderOnC(Integer pageNum,Integer pageSize) {
        return platformQueryOrderService.queryOrderComplete(pageNum,pageSize);
    }

    /**
    * @Author: chencong
    * @Description: 根据司机姓名和货主DTO
    * @DateTime: 17:34 2022/8/16
    * @Params: [pageNum, pageSize]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderOnCon")
    public Result queryOrderOnCondition(Integer pageNum, Integer pageSize, QueryOrderDTO queryOrder) {
        try{
            return platformQueryOrderService.queryOrderOnCondition(pageNum,pageSize,queryOrder);
        }catch (Exception e){
            return Result.fail("信息不对");
        }

    }

    /**
    * @Author: chencong
    * @Description: 通过司机姓名查询订单
    * @DateTime: 19:52 2022/8/18
    * @Params: [pageNum, pageSize, driverName]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderByDName")
    public Result queryOrderListByDriverName(Integer pageNum,Integer pageSize,String driverName) {
        return platformQueryOrderService.queryOrderListByDriverName(pageNum,pageSize,driverName);
    }

    /**
    * @Author: chencong
    * @Description: 通过货主姓名查询订单
    * @DateTime: 19:52 2022/8/18
    * @Params: [pageNum, pageSize, shipperName]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderBySName")
    public Result queryOrderListByShipperName(Integer pageNum,Integer pageSize,String shipperName) {
        return platformQueryOrderService.queryOrderListByShipperName(pageNum,pageSize,shipperName);
    }

    /**
    * @Author: chencong
    * @Description: 客服取消订单：其中：orderId表示订单ID，orderCancelType表示取消类型（具体含义见语雀数据模型），orderCancelReason必写，orderCancelDescription选填
    * @DateTime: 16:51 2022/8/18
    * @Params: [orderId, orderCancelType, orderCancelReason, orderCancelDescription]
    * @Return com.ymm.platform.api.utils.Result
    */
    @GetMapping("/quitOrder")
    public Result editOrderState(Long orderId, Integer orderCancelType, Integer orderCancelReason, String orderCancelDescription) {
        log.info(String.valueOf(orderId)+orderCancelDescription);

        Boolean res = systemOrderService.cancelOrderByBackstage(orderId, orderCancelType, orderCancelReason, orderCancelDescription).getData();
        return Result.success(res);
    }

    /**
    * @Author: chencong
    * @Description: 通过订单ID查询订单详情
    * @DateTime: 19:52 2022/8/18
    * @Params: [orderId]
    * @Return com.ymm.platform.api.utils.Result
    */
    @RequestMapping("/getOrderById")
    public Result queryOrderDetailsById(Long orderId) {
//        if(orderId.equals(null)){
//            return Result.fail("输入订单号错误，查不到该订单");
//        }
        return platformQueryOrderService.queryOrderDetailsById(orderId);
    }
}
